
import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts";

const client = new Client({
  hostname: 'localhost',
  port: 5432,
  database: 'test',
  user: 'root',
  password: 'locnelor',
})

await client.connect();
export const findMany = async <T>(sql: string, args?: any[]) => {
  try {
    const result = await client.queryObject(sql);
    return result.rows as T;
  } catch (error) {
    console.log(error)
    return null
  }
}
export const findOne = async <T>(sql: string, args?: any[]) => {
  try {
    const result = await client.queryObject(sql, args);
    return result.rows[0] as T;
  } catch (error) {
    console.log(error)
    return null;
  }
}
export default client